(function (vc) {

    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addProductPriceRuleInfo: {
                ruleId: '',
                ruleId: '',
                ruleName: '',
                price: '',
                otPrice: '',
                vipPrice: '',
                ownerPrice: '',
                deduction: '',
                ruleType: '',
                priceBase: '1',
                otPriceBase: '1',
                vipPriceBase: '1',
                ownerPriceBase: '1',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addProductPriceRule', 'openAddProductPriceRuleModal', function () {
                $('#addProductPriceRuleModel').modal('show');
            });
        },
        methods: {
            addProductPriceRuleValidate() {
                return vc.validate.validate({
                    addProductPriceRuleInfo: $that.addProductPriceRuleInfo
                }, {
                    'addProductPriceRuleInfo.ruleName': [{
                        limit: "required",
                        param: "",
                        errInfo: "策略名称不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "64",
                        errInfo: "策略名称不能超过64"
                    },
                    ],
                    'addProductPriceRuleInfo.price': [{
                        limit: "required",
                        param: "",
                        errInfo: "销售金额不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "8",
                        errInfo: "销售金额不能超过8"
                    },
                    ],
                    'addProductPriceRuleInfo.otPrice': [{
                        limit: "required",
                        param: "",
                        errInfo: "市场价不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "8",
                        errInfo: "市场价不能超过8"
                    },
                    ],
                    'addProductPriceRuleInfo.vipPrice': [{
                        limit: "required",
                        param: "",
                        errInfo: "会员价不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "8",
                        errInfo: "会员价不能超过8"
                    },
                    ],
                    'addProductPriceRuleInfo.ownerPrice': [{
                        limit: "required",
                        param: "",
                        errInfo: "业主价不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "8",
                        errInfo: "业主价不能超过8"
                    },
                    ],
                    'addProductPriceRuleInfo.deduction': [{
                        limit: "required",
                        param: "",
                        errInfo: "物业抵扣金'不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "8",
                        errInfo: "物业抵扣金'不能超过8"
                    },
                    ],
                });
            },
            saveProductPriceRuleInfo: function () {
                if (!$that.addProductPriceRuleValidate()) {
                    vc.toast(vc.validate.errInfo);

                    return;
                }

                $that.addProductPriceRuleInfo.shopId = vc.getCurrentCommunity().shopId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addProductPriceRuleInfo);
                    $('#addProductPriceRuleModel').modal('hide');
                    return;
                }

                vc.http.apiPost(
                    'productPriceRule.saveProductPriceRule',
                    JSON.stringify($that.addProductPriceRuleInfo), {
                    emulateJSON: true
                },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addProductPriceRuleModel').modal('hide');
                            $that.clearAddProductPriceRuleInfo();
                            vc.emit('productPriceRuleManage', 'listProductPriceRule', {});

                            return;
                        }
                        vc.toast(_json.msg);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },
            clearAddProductPriceRuleInfo: function () {
                $that.addProductPriceRuleInfo = {
                    ruleId: '',
                    ruleName: '',
                    price: '',
                    otPrice: '',
                    vipPrice: '',
                    ownerPrice: '',
                    deduction: '',
                    ruleType: '',
                    priceBase: '1',
                    otPriceBase: '1',
                    vipPriceBase: '1',
                    ownerPriceBase: '1',
                };
            }
        }
    });

})(window.vc);